﻿namespace SharpF2.Components
{
	using System;
	using System.Collections.Generic;
	using System.Windows.Controls;
	using System.Windows.Input;

	/// <summary>
	/// Interaction logic for IntegerBox
	/// </summary>
	public class IntegerBox : TextBox
	{
		#region Private Members

		private static bool AreAllValidNumericChars(IEnumerable<char> text)
		{
			foreach (var c in text)
				if (!Char.IsNumber(c))
					return false;
			return true;
		}

		#endregion

		#region Protected Members

		protected override void OnPreviewTextInput(TextCompositionEventArgs e)
		{
			e.Handled = !AreAllValidNumericChars(e.Text);
			base.OnPreviewTextInput(e);
		}

		#endregion
	}
}